﻿namespace UsefulTools.Core
{
    using System;
    using System.Diagnostics;

    public interface IMessageService
    {
        void ShowMessage(IWindow owner, string message);

        void ShowWarning(IWindow owner, string message);

        void ShowFatalError(IWindow owner, string message);

 
        bool ShowYesNoQuestion(IWindow owner, string message);

        void ShowError(IWindow owner, string message);
    }

    public static class MessageServiceExtensions
    {
        public static void ShowMessage(this IMessageService service, string message, IWindow view = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            service.ShowMessage(view, message);
        }


        public static void ShowWarning(this IMessageService service, string message, IWindow view = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            Trace.TraceWarning(message);

            service.ShowWarning(view, message);
        }

        public static void ShowFatalError(this IMessageService service, string message, IWindow view = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            Trace.TraceError(message);
            service.ShowFatalError(view, message);
        }



        public static bool ShowYesNoQuestion(this IMessageService service, string message, IWindow view = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            return service.ShowYesNoQuestion(view, message);
        }

        public static void ShowFatalError(this IMessageService service, Exception exception, IWindow view = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            Trace.TraceError(exception.Message);

            service.ShowFatalError(view, exception.ToString());
        }

        public static void ShowError(this IMessageService service, Exception exception, IWindow view = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            Trace.TraceError(exception.Message);

            service.ShowError(view, exception.Message);
        }
        public static void ShowError(this IMessageService service, string message, IWindow view = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }
            Trace.TraceError(message);
            service.ShowError(view, message);
        }
    }
}